package com.cdj.common.behavior;

import androidx.annotation.NonNull;

import com.cdj.common.ILoadingBehavior;
import com.cdj.common.view.IRefreshAdapterHolder;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

/**
 * ---------------------------------------------------------<br />
 * desc：<br />
 * author：chendeji <br />
 * date：2021/7/5<br />
 * email：18701434169@163.com<br />
 * qq: 781571323
 * wx: melody_2009
 * ---------------------------------------------------------<br />
 */
public abstract class BaseRefreshListLoadingBehavior<T, Result> extends BaseLoadingBehavior<T, Result>{

    public BaseRefreshListLoadingBehavior(ILoadingBehavior defualt) {
        super(defualt);
    }

    protected IRefreshAdapterHolder<Result> adapterHolder;
    public void setAdapterHolder(IRefreshAdapterHolder<Result> adapterHolder) {
        this.adapterHolder = adapterHolder;
        this.adapterHolder.setLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                loadmore();
                refreshLayout.finishLoadMore(500);
            }
        });
        this.adapterHolder.setRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                refresh();
                refreshLayout.finishRefresh(500);
            }
        });
    }

    protected abstract void refresh();
    protected abstract void loadmore();

}
